import { createApp } from "vue";
import Toast from "./index.vue";

export function toast(message: string, timer = 3000) {
    console.log("toast", message);
    const toastApp = createApp(Toast, { message });
    const toastRoot = document.createElement("div");
    document.body.appendChild(toastRoot);
    toastApp.mount(toastRoot);

    // 隐藏并移除toast组件
    setTimeout(() => {
        toastApp.unmount();
        document.body.removeChild(toastRoot);
    }, timer); // 3秒后自动隐藏
}

// export function install(app: any) {
//   // 将Toast函数挂载到全局
//   app.config.globalProperties.$toast = createToast;
// }
